class Observer {
  constructor (data){
    this.walk(data)
  }
  // 1. 遍历所有的属性
  walk (data) {
    if (!data || typeof data !== 'object') {return }
    Object.keys(data).forEach(key=>{
      this.defineReactive(data,key,data[key])
    })
  }
  // 2. 将所有的属性转为动态属性
  defineReactive (obj,key,value) {
    this.walk(obj[key])
    let that=this
    let dep=new Dep()
    Object.defineProperty(obj,key,{
      enumerable:true,
      configurable:true,
      get() {
        Dep.target && dep.addSub(Dep.target)
        return value
      },
      set(v) {
        if (v===value){return}
        value=v
        that.walk(value)
        dep.notify()
      }
    })
  }
}
